//******************************************************************************
// CLASS SUBASEACCOUNT
//******************************************************************************
unit SUAccount;

interface
  uses
    SuStealth, Windows;

  Type
    PAccount = class
      private
        class var _Instance : PAccount;

        constructor Create;
        function SinGetAccountName: String;
        function SinGetLastLogin: TDateTime;
        function SinGetLastLogout: TDatetime;
        function SinGetPCOnDC: Boolean;
        function SinGetProfileShardName: String;
        function SinGetProxyIP: String;
        function SinGetProxyPort: Word;
        function SinGetRCStatus: Boolean;
        function SinGetShardName: String;
        function SinIsConnected: Boolean;
        function SinIsProxyUsed: Boolean;
        procedure SinSetPCOnDC(const Value: Boolean);
        procedure SinSetRCStatus(const Value: Boolean);
      public
        class function GetInstance():PAccount;

        function Login():Boolean; overload; virtual;
        function Logout():Boolean; virtual;
        function ChangeAccount(SName:String):Integer; virtual;
        function Login(SName:String):Integer; overload; virtual;
        function Login(SName:String;MaxDelay:Cardinal):Integer; overload; virtual;

        property AccountName      : String    read SinGetAccountName;
        property RCStatus         : Boolean   read SinGetRCStatus write SinSetRCStatus;
        property Connected        : Boolean   read SinIsConnected;
        property PCOnDC           : Boolean   read SinGetPCOnDC   write SinSetPCOnDC;
        property ProxyIP          : String    read SinGetProxyIP;
        property ProxyPort        : Word      read SinGetProxyPort;
        property ProxyIsEnabled   : Boolean   read SinIsProxyUsed;
        property ShardName        : String    read SinGetShardName;
        property ProfileShardName : String    read SinGetProfileShardName;
        property LastLogin        : TDateTime read SinGetLastLogin;
        property LastLogout       : TDatetime read SinGetLastLogout;
    end;

implementation

{ PAccount }

function PAccount.ChangeAccount(SName: String): Integer;
begin
  Result := Script.Connection.ChangeProfile(SName);
end;

constructor PAccount.Create;
begin
  //dont Use!!
end;

class function PAccount.GetInstance: PAccount;
begin
  if not Assigned(_Instance) then _Instance := PAccount.Create;
  Result := _Instance;
end;

function PAccount.Login: Boolean;
begin
  Result := False;
  if(Connected)then exit;
  Script.Connection.Connect;
  Result := True;
end;

function PAccount.Login(SName: String; MaxDelay: Cardinal): Integer;
var
  tick : Cardinal;
begin
  Result := Login(SName);
  if(Result = 0)then
  begin
    tick := GetTickCount + MaxDelay;
    while(not Connected) and (GetTickCount < tick)do
    begin
      Script.Wait(50);
    end;
    Result := -5;
  end;
  if(Connected)then Result := 0;
end;

function PAccount.Login(SName: String): Integer;
begin
  Result := 0;
  if(AccountName <> SName)then
  begin
    Result := ChangeAccount(SName);
    if(Result <> 0)then exit;
  end;
  if(Connected) then exit;
  Login;
end;

function PAccount.Logout: Boolean;
begin
  Result := False;
  if(not Connected)then exit;
  Script.Connection.Disconnect;
  Result := True;
end;

function PAccount.SinGetAccountName: String;
begin
  Result := Script.Connection.ProfileName;
end;

function PAccount.SinGetLastLogin: TDateTime;
begin
  Result := Script.Connection.ConnectedTime;
end;

function PAccount.SinGetLastLogout: TDatetime;
begin
  Result := Script.Connection.DisconnectedTime;
end;

function PAccount.SinGetPCOnDC: Boolean;
begin
  Result := Script.Connection.PauseScriptOnDisconnectStatus;
end;

function PAccount.SinGetProfileShardName: String;
begin
  Result := Script.Connection.ProfileShardName;
end;

function PAccount.SinGetProxyIP: String;
begin
  Result := Script.Connection.ProxyIP;
end;

function PAccount.SinGetProxyPort: Word;
begin
  Result := Script.Connection.ProxyPort;
end;

function PAccount.SinGetRCStatus: Boolean;
begin
  Result := Script.Connection.ARStatus;
end;

function PAccount.SinGetShardName: String;
begin
  Result := Script.Connection.ShardName;
end;

function PAccount.SinIsConnected: Boolean;
begin
  Result := Script.Connection.Connected;
end;

function PAccount.SinIsProxyUsed: Boolean;
begin
  Result := Script.Connection.ProxyUsed;
end;

procedure PAccount.SinSetPCOnDC(const Value: Boolean);
begin
  Script.Connection.PauseScriptOnDisconnectStatus := Value;
end;

procedure PAccount.SinSetRCStatus(const Value: Boolean);
begin
  Script.Connection.ARStatus := Value;
end;

end.
